var AjaxTimeout=5000;
var apipath='';
var test=1;
if(typeof(path)=='undefined'){
	path='.';
}
if(test==1){
	A.showlogtype=1;
	apipath='api';
	htmlpath='html/';
}else{
	A.showlogtype=0;
	apipath=path+'';
	htmlpath=path+'/html/';
}
//ajax api
function AjaxPost(url,data,callback,Async,obj){
	if(url.indexOf('http://')==-1){
		url =apipath+url;
	}
	var isasync=true;
	var relust;
	if(Async!=null)isasync=Async;
	A.ajax({
		url:url,
		data:data,
		type:'POST',
		dataType:'json',
		async:isasync,
		error:function(textstatus,errorCode){
			A.ShowLog(url,':',errorCode);
		},
		success:function (data, textStatus) {
			if(typeof(data)=='string'){
				data=eval('('+data+')');
			}
			if(typeof(callback)=='function')
			{
				callback(data,obj);
			}
			relust=data;
		},
		setTimeout:AjaxTimeout
	});
	return relust;
}
//
function printf(id,data){
	for(a in data){
		var obj=$(id).find('[name="'+a+'"]');
		var dt=$(obj).attr('dt');
		if(dt==null||dt=='modify')
		{	if(obj.attr('type')=='radio'){

				obj.each(function(){
					if(this.value==data[a]){
						this.checked=true;
					}
				});
 
			}	
			else if(obj.is('input')||obj.is('select')){
				$(obj).val(data[a]);
			} else{
				$(obj).text(data[a]);
			}
		}else if(dt=='l')	
		{
			var str=$(obj).attr('list');
			var txt=eval('('+str+'['+data[a]+'])')
			$(obj).text(txt);
		}else if(dt=='c'){
			var str=data[a].replaceAll("\n","<br/>");
			$(obj).html(str);
		}else if(dt=='w'){
			var str=$(obj).attr('str');
			str=str.replaceAll("%1",data[a]);
			$(obj).html(str);
			
		}else if(dt=="i"){
			if(data[a]){
				$(obj).attr('src', apipath+'/common/showImage?fileName=slt'+data[a])
			}
		}
		else if(dt=="nop"){

		}
	}
}

function getParamFromUrl(name){
	    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null) {
            return null;
        }
        else {
            return results[1];
        }
}

function getFormData(form){
	var data=new Object();
	var curform =$(form);
	$(form).find('[name]').each(function(i,el){
			var inputval,obj = $(el);	
			if(obj.attr('type')=='file'){
				return true;
			}
			if(obj.is(":radio")){
				inputval=curform.find(":radio[name='"+obj.attr("name")+"']:checked").val();
				inputval= inputval===undef ? "" : inputval;
			}else if(obj.is(":checkbox")){
				inputval="";
				curform.find(":checkbox[name='"+obj.attr("name")+"']:checked").each(function(){ 
					inputval +=$(this).val()+','; 
				});
				inputval= inputval===undef ? "" : inputval;
			}else{

				inputval=obj.val();
			}

			if(obj.attr('type')!='password')
			{
				if(inputval!='')
				{	
					inputval=$.trim(inputval);
				}
			}
			else{
				if(obj.attr('md5')){
					inputval=$.md5(inputval);
				}else{
					inputval=(inputval);
				}
				

			}	


			data[this.name]=inputval;
	});
	return data;
}